<template>
	<view class="goods-item">
		<!-- 左侧内容 -->
		<view class="goods-item-left">
			<radio @click="radioClickHandel" :checked="goods.goods_state" color="#c00000" v-if="showRadio" />
			<image class="goods-img" :src="goods.goods_small_logo || defaultPic" mode=""></image>
		</view>
		<!-- 右侧内容 -->
		<view class="goods-item-right">
			<view class="goods-info">
				<view class="goods-title">{{goods.goods_name}}</view>
				<view class="goods-box">
					<view class="goods-price">￥{{goods.goods_price | tofiexd}}</view>
					<uni-number-box @change="numChangeHanldel" min="1" :value="goods.goods_count" v-if="showBox"></uni-number-box> 
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-goods",
		data() {
			return {
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		props: {
			goods: {
				type: Object,
				default: {}
			},
			
			// 勾选框是否显示
			showRadio: {
				type: Boolean,
				default: false
			},
			
			// 商品数量是否显示
			showBox: {
				type: Boolean,
				default: false
			}
		},
		filters: {
			tofiexd(num) {
				return Number(num).toFixed(2)
			}
		},
		methods: {
			radioClickHandel() {
				this.$emit('radio-click', {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state
				})
			},
			
			numChangeHanldel(val) {
				this.$emit('num-change', {
					goods_id: this.goods.goods_id,
					goods_count: +val
				});
			}
		}
	}
</script>

<style lang="scss">
	.goods-item {
		display: flex;
		width: 750rpx;
		box-sizing: border-box;
		padding: 10px 5px;
		border-bottom: 1px solid #f0f0f0;
		.goods-item-left {
			display: flex;
			align-items: center;
			justify-content: center;
			.goods-img {
				width: 100px;
				height: 100px;
				display: block;
				margin-right: 5px;
			}
		}
		
		.goods-item-right {
			flex: 1;
			.goods-info {
				height: 100px;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.goods-title {
					font-size: 12px;
				}
				.goods-box {
					display: flex;
					justify-content: space-between;
					align-items: center;
					.goods-price {
						font-size: 16px;
						color: #c00000;
					}
				}
				
			}
		}
	}
	
</style>